package com.doit.day01;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class MyTools {

    public static Jedis getJedis()  {
        Properties props = new Properties();
        try {
            props.load(new FileReader("D:\\develop\\ideaWorkSpace\\doit45\\RedisDemo\\src\\main\\resources\\myProperties.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String jedisHost = props.getProperty("jedisHost");
        int jedisPort = Integer.parseInt(props.getProperty("jedisPort"));

        JedisPool jedisPool = new JedisPool(jedisHost,jedisPort);
        return jedisPool.getResource();
    }

    public static Connection getMysql() throws Exception {
        Properties props = new Properties();
        try {
            props.load(new FileReader("D:\\develop\\ideaWorkSpace\\doit45\\RedisDemo\\src\\main\\resources\\myProperties.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String mysqlUrl = props.getProperty("mysqlUrl");
        String user = props.getProperty("mysqlUser");
        String password = props.getProperty("mysqlPassword");

        return DriverManager.getConnection(mysqlUrl,user,password);

    }

}
